<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        body {}
    </style>
</head>

<style>
    .huoche:before {
        content: url(../image/menu/huoche.png);
    }

    .picifahuo:before {
        content: url(../image/menu/picifahuo.png);
    }

    .ruku:before {
        content: url(../image/menu/ruku.png);
    }

    .caigouruku:before {
        content: url(../image/menu/caigouruku.png);
    }

    .shouhuoruku:before {
        content: url(../image/menu/shouhuoruku.png);
    }

    .zongchengruku:before {
        content: url(../image/menu/zongchengruku.png);
    }

    .hkruku:before {
        content: url(../image/menu/hkruku.png);
    }

    .chuku:before {
        content: url(../image/menu/chuku.png);
    }

    .zongchengchuku:before {
        content: url(../image/menu/zongchengchuku.png);
    }

    .hkchuku:before {
        content: url(../image/menu/hkchuku.png);
    }

    .kuneizhuanyi:before {
        content: url(../image/menu/kuneizhuanyi.png);
    }

    .kujianzhuanyi:before {
        content: url(../image/menu/kujianzhuanyi.png);
    }

    .cangkuxianyouliang:before {
        content: url(../image/menu/cangkuxianyouliang.png);
    }

    .xiaoshouchuku:before {
        content: url(../image/menu/xiaoshouchuku.png);
    }

    .cangkupandian:before {
        content: url(../image/menu/cangkupandian.png);
    }

    .fahuoguanli:before {
        content: url(../image/menu/fahuoguanli.png);
    }

    .fahuotuo:before {
        content: url(../image/menu/fahuotuo.png);
    }

    .fahuojiancedan:before {
        content: url(../image/menu/fahuojiancedan.png);
    }

    .fahuoguanliyouhua:before {
        content: url(../image/menu/fahuoguanliyouhua.png);
    }

    .shouhuoyanzheng:before {
        content: url(../image/menu/shouhuoyanzheng.png);
    }

    .daochangshouhuo:before {
        content: url(../image/menu/daochangshouhuo.png);
    }

    .kanbanshouhuo:before {
        content: url(../image/menu/kanbanshouhuo.png);
    }

    .yijianshouhuo:before {
        content: url(../image/menu/yijianshouhuo.png);
    }

    .andongjiaoliao:before {
        content: url(../image/menu/andongjiaoliao.png);
    }

    .peisongbeihuo:before {
        content: url(../image/menu/peisongbeihuo.png);
    }

    .xianbianshangliao:before {
        content: url(../image/menu/xianbianshangliao.png);
    }

    .queren:before {
        content: url(../image/menu/queren.png);
    }

    .shengchanshangliao:before {
        content: url(../image/menu/shengchanshangliao.png);
    }

    .chaungjianjiancedan:before {
        content: url(../image/menu/chaungjianjiancedan.png);
    }

    .jiancedanchuli:before {
        content: url(../image/menu/jiancedanchuli.png);
    }

    .wentiluru:before {
        content: url(../image/menu/wentiluru.png);
    }

    .shiyongdengji:before {
        content: url(../image/menu/shiyongdengji.png);
    }

    .daoju:before {
        content: url(../image/menu/daoju.png);
    }

    .baofei:before {
        content: url(../image/menu/baofei.png);
    }

    .dayin:before {
        content: url(../image/menu/dayin.png);
    }

    .saomiao:before {
        content: url(../image/menu/saomiao.png);
    }

    .bangding:before {
        content: url(../image/menu/bangding.png);
    }

    .gongwei:before {
        content: url(../image/menu/gongwei.png);
    }

    .gongxu:before {
        content: url(../image/menu/gongxu.png);
    }

    .wangong:before {
        content: url(../image/menu/wangong.png);
    }

    .faqi:before {
        content: url(../image/menu/faqi.png);
    }

    .renwu:before {
        content: url(../image/menu/renwu.png);
    }

    .shebeiguanli:before {
        content: url(../image/menu/shebeiguanli.png);
    }

    .muju:before {
        content: url(../image/menu/muju.png);
    }

    .jiaoyan:before {
        content: url(../image/menu/jiaoyan.png);
    }

    .tuopan:before {
        content: url(../image/menu/tuopan.png);
    }

    .songjiandan:before {
        content: url(../image/menu/songjiandan.png);
    }

    .xinhaojiankong:before {
        content: url(../image/menu/xinhaojiankong.png);
    }

    .yichang:before {
        content: url(../image/menu/yichang.png);
    }

    .yichangchaxun:before {
        content: url(../image/menu/yichangchaxun.png);
    }

    .chakan:before {
        content: url(../image/menu/chakan.png);
    }

    .geli:before {
        content: url(../image/menu/geli.png);
    }

    .zhuanhuan:before {
        content: url(../image/menu/zhuanhuan.png);
    }

    .chengpinfahuo:before {
        content: url(../image/menu/chengpinfahuo.png);
    }

    .beijianfahuo:before {
        content: url(../image/menu/beijianfahuo.png);
    }

    .barchart:before {
        content: url(../image/menu/barchart.png);
    }

    .linechart:before {
        content: url(../image/menu/linechart.png);
    }

    .piechart:before {
        content: url(../image/menu/piechart.png);
    }

    .PLC:before {
        content: url(../image/menu/PLC.png);
    }

    .gzfx:before {
        content: url(../image/menu/gzfx.png);
    }
</style>

<body>

    <header  style="background-color: #03a9f4; position: fixed; z-index: 9999; height: auto;width: 100%; padding: 15px;" id="header">
        <div class="aui-title" id="title" style="width: 100%; box-sizing: border-box;">
            <!-- 第一行：系统名称（靠左） -->
            <div style="text-align: left; margin-bottom: 10px;">
                <span style="font-size: 18px; color: #fff; font-weight: bold;">石川岛设备管理系统</span>
            </div>
            
            <!-- 第二行：图片（左）和标语（右） -->
            <div style="display: flex; align-items: center; justify-content: space-between;">
                <!-- 图片（靠左） -->
                <img src="../image/mainMenuLeft.png" style="width: 80px; height: 80px; margin: 0;">
                
                <!-- 标语组（靠右分三行） -->
                <div style="text-align: right;">
                    <p style="font-size: 14px; color: #fff; margin: 0 0 5px 0;">让设备少出故障，让管理少走弯路！</p>
                    <p style="font-size: 12px; color: #fff; margin: 5px 0;">每一次维护都精准</p>
                    <p style="font-size: 12px; color: #fff; margin: 5px 0;">每一台设备都可控</p>
                </div>
            </div>
    
        </div>
    </header>


    <div class="aui-content aui-margin-b-15" style="margin-top:2.25rem;position:fixed;display:table;
    background-color: #03a9f4;top:0;left:0;right:0;bottom:0; z-index: 9999;">
        <div class="aui-grid" style="display: none;">
            <div class="aui-list aui-form-list fixed-margin">
                <div class="aui-list-item" style="background-color: #03a9f4;">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="color:#FFFFFF;">
                            工厂>
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请选择工厂" style="color:#FFFFFF;" id="factoryName" readonly
                                onclick="getFactory()">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="aui-content aui-margin-b-15" ">
        <div class="aui-grid" >
            <!-- 设备数据总览 -->
            <div class="aui-row" id="eqDataGrid" style="margin-top: 15%;"></div>
            <!-- 菜单 -->
            <div class="aui-row" id="menuGrid" style="margin-top: -25%;"></div>
        </div>
    </div>

    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item aui-active" tapmode>
            <i class="aui-iconfont aui-icon-home"></i>
            <div class="aui-bar-tab-label">首页</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="goPage('emEquipment')">
            <img src="../image/equipmentManagement.png" style="width: 32px; height: 30px; ">
            <div class="aui-bar-tab-label" style="margin-top: -9px;">设备管理</div>
        </div>
        <!-- <div class="aui-bar-tab-item" tapmode onclick="toPhoto()">
            <i class="aui-iconfont aui-icon-camera"></i>
            <div class="aui-bar-tab-label">拍照</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toScanner()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toMsgList()">
            <i class="aui-iconfont aui-icon-mail"></i>
            <div class="aui-bar-tab-label" id = "message">消息</div>
        </div> -->
        <div class="aui-bar-tab-item" tapmode onclick="setPerson()">
            <i class="aui-iconfont aui-icon-my"></i>
            <div class="aui-bar-tab-label">我的</div>
        </div>
    </footer>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    //极光
    var jpush = null;
    //初始化
    apiready = function () {

        console.log("registrationId:" + 11);


        api.addEventListener({
            name: 'loginSuccess'
        }, function (ret, err) {

            if (ret) {

                $api.html($api.byId("menuGrid"), "");
                window.location.reload();

            } else { }
        });

        jpush = api.require('ajpush');

        jpush.setAuth({
            auth: true
        }, function (ret) {
            if (ret) {
                // alert(ret)
                // alert(ret.status)
            }
        });

        //id
        jpush.getRegistrationId(function (ret) {
            var registrationId = ret.id;
             console.log("registrationId:" + registrationId);

            //根据用户绑定id
            saveRegistrationId(registrationId);

        });

        api.addEventListener({
            name: 'appintent'
        }, function (ret, err) {
            // alert('通知被点击，收到数据：\n' + JSON.stringify(ret)); //监听通知被点击后收到的数据
            if (ret && ret.appParam.ajpush) {

                var ajpush = ret.appParam.ajpush;
                var id = ajpush.id;
                console.log(id);
                var title = ajpush.title;
                var content = ajpush.content;
                var extra = ajpush.extra;
                console.log(extra);

                alert('通知被点击，收到数据：\n' + content);
            }
        });

        api.addEventListener({
            name: 'pause'
        }, function (ret, err) {
            onPause(); //监听应用进入后台，通知jpush暂停事件
            // document.getElementById('message').style.color = 'red';
            // document.getElementById("message").textContent = "消息+1"
        })

        api.addEventListener({
            name: 'resume'
        }, function (ret, err) {
            onResume(); //监听应用恢复到前台，通知jpush恢复事件
            // document.getElementById('message').style.color = 'red';
            // document.getElementById("message").textContent = "消息+1"
        })

        //极光推送初始化
        initJPush();


        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            if (ret) {
                //alert( JSON.stringify( ret ) );
                api.confirm({
                    title: '退出提示',
                    msg: '确定要退出程序吗?',
                    buttons: ['确定', '取消']
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 1) {
                        api.closeWidget({
                            silent: true
                        });
                    }
                });
            } else {
                alert(JSON.stringify(err));
            }
        });
        //获取菜单
        searchMenu();
        //获取设备总览
        searchEqData();
        //初始化根据人员显示工厂
        setSiteByLoginUser();


    }


    //根据用户绑定ID
    function saveRegistrationId(registrationId) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveRegistrationId";
        var data = {
            values: {
                registrationId: registrationId,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    // console.log("registrationId绑定成功");

                    //失败
                } else if (myobj.code == "1") {
                    // console.log("registrationId绑定失败");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //极光推送初始化
    function initJPush() {
        jpush.init(function (ret, err) {
            if (ret && ret.status) {
                // console.log('极光推送初始化：操作成功!');
            } else {
                // console.log('极光推送初始化：操作失败!');
            }
        });
    }

    //极光绑定别名
    function bindAliasAndTags() {
        var un = localStorage.getItem('un');
        var param = {
            alias: un,
            tags: []
        };
        jpush.bindAliasAndTags(param, function (ret, err) {
            console.log('极光绑定别名处理结果：\n' + JSON.stringify(ret));
        });
    }

    //极光推送-app恢复
    function onResume() {
        jpush.onResume();
        console.log('JPush onResume');
    }

    //极光推送-app暂停
    function onPause() {
        jpush.onPause();
        console.log('JPush onPause');
    }

    function setSiteByLoginUser() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/showSite";
        var data = {
            values: {
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == 0) {
                    $("#factoryId").val(myobj.sysid);
                    $("#factoryName").val(myobj.name);
                } else if (myobj.code == 1) {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }

            }
        });
    }

    //工序选择后回调函数
    function setSite(sysid, name) {
        $("#factoryId").val(sysid);
        localStorage.setItem('tenantId', sysid);
        $("#factoryName").val(name);
        //真正存到数据库中，将sys_user表data_role字段更新成工厂ID
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/updateSite";
        var data = {
            values: {
                un: un,
                siteId: sysid
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "选择工厂成功!",
                        duration: 3000
                    });
                } else if (myobj.code == 1) {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }

            }
        });
    }



    function getFactory() {
        api.openWin({
            name: "factory_win",
            url: "factory_win.html",
        });
    }

    
    //获取设备总览数据
    function searchEqData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchEqData";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var html = "<div id = 'box'  style='margin-top: 5rem;' ";
                    var list = eval(myobj.list);
                    //遍历
                    html += "<div  style='font-weight: bold;height:40px;width:100%;font-size: 20px;background-color: #f1eeee; padding-left: 5px;color: #2f2929;font-weight: 200;'>";
                        html += "<span style='display:inline-block;width:3px;height:12px;background-color:#03a9f4;vertical-align:middle;margin-right:6px;margin-left:5px;margin-top:-4px;'></span>";
                        html += "<span style='font-weight: bold;'>"+'数据总览'+'</span>';
                        html += "</div>";
                        // 外层容器使用flex布局强制一行显示
                        html += "<div class='aui-row' style='margin-bottom:4px;display:flex;justify-content:space-around;'>";

                        // 只显示三个数据项，确保在一行
                        for (var j = 0; j < 3 && j < list.length; j++) {
                            html += "<div class='data-item' style='width:33.33%;text-align:center;padding:10px;box-sizing:border-box;'>";
                            // value在上，使用对应颜色
                            html += "<div class='value' style='color:" + list[j].color + ";font-size:20px;font-weight:bold;'>" + list[j].value + "</div>";
                            // label在下
                            html += "<div class='label' style='font-size:14px;margin-top:4px;color:#666;'>" + list[j].label + "</div>";
                            html += "</div>";
                        }
                        html += "</div>";
                    html += "</div>";
                    // console.log("htmlhtmlhtml",html);
                    $api.html($api.byId("eqDataGrid"), html);
                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //获取菜单
    function searchMenu() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchMenuNew";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    // 关键修复：闭合box容器起始标签，删除多余空格
                    var html = "<div id='box' style='margin-top: 5rem;'>";
                    var list = eval(myobj.list);
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        // 标题容器：统一样式，添加line-height确保垂直居中
                        html += "<div style=' height:10px; width:100%;  background-color:#f1eeee; padding-left:5px; color:#2f2929; font-weight:200; line-height:20px;'></div>";
                        html += "<div style='margin-top:1px; height:40px; width:100%; font-size:20px; background-color:#ffffff; padding-left:5px; color:#2f2929; font-weight:200; line-height:40px;'>";
                        // 蓝色竖杠：优化尺寸和对齐，删除负margin
                        html += "<span style='display:inline-block; width:3px; height:12px; background-color:#03a9f4; vertical-align:middle; margin-right:6px; margin-left:2px; margin-top:-4px;'></span>";
                        // 标题文字：确保字体加粗统一
                        html += "<span style='font-weight:bold;font-size:16px;'>" + list[i].title + "</span>";
                        html += "</div>";
                        
                        // 菜单内容区域
                        html += "<div class='aui-row' style='margin-bottom:40px;'>";
                        for (var j = 0; j < list[i].children.length; j++) {
                            html += "    <div class='aui-col-xs-3' onclick='goPage(\"" + list[i].children[j].url + "\");'>";
                            // 图标优化：设置尺寸和布局，确保显示正常
                            html += "    <i class='aui-iconfont " + (list[i].children[j].icon || "") + "' style='font-size:24px; display:block; margin:0 auto 5px; text-align:center;'></i>";
                            html += "    <div class='aui-grid-label' style='text-align:center;'>" + list[i].children[j].title + "</div>";
                            html += "    </div>";
                        }
                        html += "</div>";
                    }
                    html += "</div>"; // 闭合box容器
                $api.html($api.byId("menuGrid"), html);
                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //跳转页面
    function goPage(url) {
        var arr = url.split("?");
        var name = arr[0];
        var query = {};
        if (arr.length > 1) {
            //参数
            var paramStr = arr[1];
            var paramArr = paramStr.split("&");
            for (var i = 0; i < paramArr.length; i++) {
                var params = paramArr[i].split("=");
                query[params[0]] = params[1];
            }

        }
        //打开页面
        api.openWin({
            name: name,
            url: name + '.html',
            pageParam: {
                query: query,
            }
        });
    }


    //拍照
    function toPhoto() {
        api.getPicture({
            sourceType: 'camera', //library    图片库//camera    相机         // albm  相册
            encodingType: 'jpg', //返回图片类型，jpg或png
            mediaValue: 'pic', //媒体类型，图片或视频
            destinationType: 'url', //返回数据类型，指定返回图片地址或图片经过base64编码后的字符串
            allowEdit: true, //是否可以选择图片后进行编辑，支持iOS及部分安卓手机
            //quality: 80,
            targetWidth: 400, //压缩后的图片宽度，图片会按比例适配此宽度
            targetHeight: 500, //压缩后的图片高度，图片会按比例适配此高度
            saveToPhotoAlbum: true //拍照或录制视频后是否保存到相册
        }, function (ret, err) {
            if (ret) {
                //alert( JSON.stringify( ret ) );
            } else {
                //alert( JSON.stringify( err ) );
            }
        });
    }

    //扫描
    function toScanner() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            // getEquipByCode(ret);
        });
    }

    //消息
    function toMsgList() {
        document.getElementById('message').style.color = 'black';
        document.getElementById("message").textContent = "消息"
        api.openWin({
            name: "msglist",
            url: "msglist.html"
        });
    }

    //个人中心
    function setPerson() {
        api.openWin({
            name: "person",
            url: "person.html"
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>